[JavaScript] How to get the uri of the .js file itself.

Posted by Vikrant Chaudhary on Stack Overflow See other posts from Stack Overflow or by Vikrant Chaudhary
Published on 2010-06-03T14:38:57Z Indexed on 2010/06/03 14:44 UTC
Read the original article Hit count: 270

Filed under:

Hi, is there a method in JavaScript by which I can find out the path/uri of the executing script.

For example:

  1. index.html includes a JavaScript file stuff.js and since stuff.js file depends on ./commons.js, it wants to include it too in the page. Problem is that stuff.js only knows the relative path of ./commons.js from itself and has no clue of full url/path.

  2. index.html includes stuff.js file as <script src="http://example.net/js/stuff.js?key=value" /> and stuff.js file wants to read the value of key. How to?

© Stack Overflow or respective owner

Related posts about JavaScript